package com.mdh.EightStudy;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author mac
 * @date 2021/9/3 2:46 下午
 */
public class CollectionConvert {
    private static List<User> users = new ArrayList<>();
    static {
        for (int i = 0; i < 10; i++) {
            User user = new User(String.valueOf(i), i << i);
            users.add(user);
        }
    }

    public static void main(String[] args) {
        List<? extends Number> numbers = MyDataOperation.arrayConverter(users);
        for (Number number : numbers) {
            System.out.println("number = " + number);
        }
    }

}

/**
 * 资源操作类
 */
class MyDataOperation{
    public static List<? extends Number> arrayConverter(List<User> src){
        return new MyData().apply(src);
    }
}
/**
 * 通过封装的形式学习java8函数式接口
 */
class MyData implements Function<List<User>, List<? extends Number>> {

    @Override
    public List<? extends Number> apply(List<User> objects) {
        return objects.stream().map(User::getLevel).collect(Collectors.toList());
    }
}

class User implements Serializable{
    private String name;

    private Integer level;

    public User() {
    }

    public User(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    public String getName() {
        return name;
    }

    public Integer getLevel() {
        return level;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }
}
